package cn.wolfcode.ss.handler;

import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

// 登陆成功之后的处理器
public class MyAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
    @Override
    public void onAuthenticationSuccess(HttpServletRequest request,
                                        HttpServletResponse response,
                                        Authentication authentication) throws IOException, ServletException {
        // 自定义登陆成功之后的逻辑
        // response.sendRedirect("/success"); -- 传统项目


        // 前后端分离项目 -- json
        response.setContentType("application/json;charset=utf-8"); //因为有中文所以需要设置编码
        String data = "{\"code\":200,\"msg\":\"登陆成功\",\"data\":\"\"}";
        response.getWriter().write(data);
    }
}
